import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loxen/utils/color.dart';

class MySubassembly {
  ///带边线按钮
  static Widget getButtonLine(
    Function() onClick, {
    String text = 'button',
    double height = 80,
    Color background = Colours.bg_color,
    Color lineColor = Colours.line_grey,
    double lineWidth = 1,
  }) {
    bool min = text.length < 4;
    return Material(
      color: background,
      child: InkWell(
        onTap: onClick,
        borderRadius: BorderRadius.all(Radius.circular(height)),
        child: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(height)),
            border: Border.all(color: lineColor, width: lineWidth),
          ),
          padding: min ? null : EdgeInsets.only(right: 30.w, left: 30.w),
          width: min ? 170.w : null,
          height: height,
          child: Center(
            child: Text(
              text,
              style: TextStyle(
                fontSize: 28.sp,
                color: Colours.text_gray,
              ),
              maxLines: 1,
            ),
          ),
        ),
      ),
    );
  }

  ///不带线条椭圆按钮
  static Widget getButton(
    Function() onClick, {
    String text = 'button',
    double height = 80,
  }) {
    bool min = text.length < 4;
    return Material(
      borderRadius: BorderRadius.all(Radius.circular(height)),
      color: onClick == null ? Colours.button_disabled : Colours.app_main,
      child: InkWell(
        onTap: onClick,
        borderRadius: BorderRadius.all(Radius.circular(height)),
        child: Container(
          padding: min ? null : EdgeInsets.only(right: 30.w, left: 30.w),
          width: min ? 170.w : null,
          height: height,
          child: Center(
            child: Text(
              text,
              style: TextStyle(
                fontSize: 28.sp,
                color: Colours.bg_color,
              ),
            ),
          ),
        ),
      ),
    );
  }

  static Widget getLoadingItem() {
    return Column(
      children: [
        Padding(
          padding: EdgeInsets.only(top: 400.h),
          child: CircularProgressIndicator(),
        ),
      ],
    );
  }

  static Widget getNullItem({String msg = '没有更多日程安排'}) {
    return Column(
      children: [
        Padding(
          padding: EdgeInsets.only(top: 400.h),
          child: Image.asset(
            'images/null_icon.png',
            width: 237.w,
            height: 152.w,
          ),
        ),
        Padding(
          padding: EdgeInsets.only(top: 20.h, bottom: 20.h),
          child: Text(
            msg,
            style: TextStyle(
              fontSize: 28.sp,
              color: Colours.dark_text_gray,
            ),
          ),
        )
      ],
    );
  }

  static Widget getBackIcon(BuildContext context,
          {Color color = Colors.white, Function() onPressed}) =>
      Material(
        color: Colors.transparent,
        child: SizedBox(
          width: 95.h,
          height: 95.h,
          child: InkWell(
              child: Icon(
                Icons.arrow_back_ios,
                size: 30.w,
                color: color,
              ),
              onTap: () {
                if (onPressed != null) {
                  onPressed.call();
                } else {
                  Navigator.of(context).pop();
                }
              }),
        ),
      );

  static Widget getSearchIcon(void Function() onPressed,
      {String url = 'images/search_icon.png', Widget text, double width, double height}) {
    if (width == null) {
      width = 30.w;
    }
    if (height == null) {
      height = 30.w;
    }
    var dataW = (95.h - width) / 2;
    var dataH = (95.h - height) / 2;
    var padding = EdgeInsets.fromLTRB(dataW, dataH, dataW, dataH);
    return Material(
      color: Colors.transparent,
      child: SizedBox(
        width: 95.h,
        height: 95.h,
        child: InkWell(
          onTap: onPressed,
          child: text != null
              ? Center(child: text)
              : Container(
                  padding: padding,
                  child: Image.asset(
                    url,
                    fit: BoxFit.fitWidth,
                  ),
                ),
        ),
      ),
    );
  }
}
